﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Com.LongER.Framework.Utils;
using Com.LongER.UI;
using Com.LongER.Business.ZDH003;
using Com.LongER.Framework.Utils.LogUtils;

public partial class ZDH003 : ABasePage
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!this.Page.IsPostBack)
        {
            Label lblPageId = (Label)Master.FindControl("lblPageId");
            lblPageId.Text = "ZDH003";

            Label lblPageName = (Label)Master.FindControl("lblPageName");
            lblPageName.Text = "车辆状态管理画面";

            //清空画面中的输入框
            #region
            proc清空_Init("0");
            #endregion

            //autocomplete
            this.txt车辆运营状态.Text = this.hid车辆运营状态.Value;
            this.txt车辆运输状态.Text = this.hid车辆运输状态.Value;
            this.txt车辆装载状态.Text = this.hid车辆装载状态.Value;
            this.txt省市.Text = this.hid省市.Value;
 
        }
    }
    protected void btn主菜单_Click(object sender, EventArgs e)
    {
        Response.Redirect("/LongER/ZAH003.aspx");
    }


    protected void btn执行_Click(object sender, EventArgs e)
    {
        //初期化处理
        #region
        //错误信息
        Label lblMsgCD = (Label)Master.FindControl("lblMsgCD");
        Label lblMsg = (Label)Master.FindControl("lblMsg");
        lblMsgCD.Text = "";
        lblMsg.Text = "";

        #endregion

        //处理区分进行确认
        if (this.txt处理区分.Text == string.Empty) //处理区分为空的场合
        {
            this.SetMessage("GTH000", "IGTH000001", MSG_LEVEL.Info);
            this.AddCssClass(this.txt处理区分, CSS_TEXT_ERROR);
            return;
        }
        else if (this.txt处理区分.Text == "1") //处理区分为1(查询)的场合
        {
            #region
            //查询时，各个控件的属性进行控制
            //proc清空_Init(this.txt处理区分.Text);

            //车牌号为空时
            if (this.txt车牌号.Text == string.Empty)
            {
                this.SetMessage("GTH002", "IGTH002002", MSG_LEVEL.Error);
                this.AddCssClass(this.txt车牌号, CSS_TEXT_ERROR);
                return;
            }
            //对象日期为空时
            else if (this.txt日期.Text == string.Empty)
            {
                this.SetMessage("GTH002", "IGTH002002", MSG_LEVEL.Error);
                this.AddCssClass(this.txt日期, CSS_TEXT_ERROR);
                return;
            }
            //对象时间为空时
            else if (this.txt时间_Hour.Text == string.Empty)
            {
                this.SetMessage("GTH002", "IGTH002002", MSG_LEVEL.Error);
                this.AddCssClass(this.txt时间_Hour, CSS_TEXT_ERROR);
                return;
            }

            //通过车牌号，日期，时间_Hour进行查询
            CZDH003 instance = new CZDH003();
            ZDH003DS.T_CHE_STADataTable dt = instance.GetT_CHE_STADetail(this.txt车牌号.Text,this.txt日期.Text,this.txt时间_Hour.Text);
            if (dt.Count <= 0)
            {
                //查询失败
                this.SetMessage("GTH002", "IGTH002001", MSG_LEVEL.Error);
                this.AddCssClass(this.txt车牌号, CSS_TEXT_ERROR);
                this.AddCssClass(this.txt日期, CSS_TEXT_ERROR);
                this.AddCssClass(this.txt时间_Hour, CSS_TEXT_ERROR);
                this.txt车牌号.Focus();
                return;
            }
            else
            {
                this.SetMessage("GTH002", "IGTH002000", MSG_LEVEL.Info);
                this.txt车辆运营状态CD.Text = dt[0].YUNYING_STA.ToString();
                this.txt车辆运营状态.Text = dt[0].YYZT_HANZI.ToString();

                this.txt车辆运输状态CD.Text = dt[0].YUNSHU_STA.ToString();
                this.txt车辆运输状态.Text = dt[0].YSZT_HANZI.ToString();

                this.txt车辆装载状态CD.Text = dt[0].ZHUANGZAI_STA.ToString();
                this.txt车辆装载状态.Text = dt[0].ZZZT_HANZI.ToString();

                this.txt车辆装载率.Text = dt[0].ZHUANGZAI_LV.ToString();

                this.txt省市CD.Text = dt[0].SUOZAI_SHENGSHI.ToString();
                this.txt省市.Text = dt[0].SZSS_HANZI.ToString();

                this.txt路段名.Text = dt[0].SUOZAI_LUDUAN.ToString();
                this.txt详细路段.Text = dt[0].DETAIL_LUDUAN.ToString();
                this.txt备注.Text = dt[0].BEIZHU.ToString();


                this.txt车牌号.Focus();
            }
            #endregion

        }
        else if (this.txt处理区分.Text == "2") //处理区分为2(登记)的场合
        {
            //登录时，各个控件的属性进行控制
            proc清空_Init(this.txt处理区分.Text);

            #region
            //登记时，各个控件的值进行检查

            //车牌号的值进行检查
            #region
            if (this.txt车牌号.Text.Trim() == string.Empty)
            {
                //车牌号为空的场合,退出登陆
                this.SetMessage("ZDH002", "IZDH002000", MSG_LEVEL.Error);
                this.AddCssClass(this.txt车牌号, CSS_TEXT_ERROR);
                this.AddCssClass(this.txt日期, CSS_TEXT_ERROR);
                this.AddCssClass(this.txt时间_Hour, CSS_TEXT_ERROR);
                return;
            }
            else
            {
                //对车牌号，日期，时间进行查询
                CZDH003 instanceSelectTChe = new CZDH003();
                ZDH003DS.T_CHE_STADataTable dtSelectTChe = instanceSelectTChe.GetT_CHE_STADetail(this.txt车牌号.Text, this.txt日期.Text, this.txt时间_Hour.Text);
                if (dtSelectTChe.Count > 0)
                {
                    //状态信息已存在场合,退出登陆
                    this.SetMessage("ZDH002", "IZDH002006", MSG_LEVEL.Error);
                    this.AddCssClass(this.txt车牌号, CSS_TEXT_ERROR);
                    this.AddCssClass(this.txt日期, CSS_TEXT_ERROR);
                    this.AddCssClass(this.txt时间_Hour, CSS_TEXT_ERROR);
                    this.txt车牌号.Focus();
                    return;
                }
            }
            #endregion

            //执行登记
            #region
            Boolean isInserted = false;
            CZDH003 instanceIst = new CZDH003();
            isInserted = instanceIst.InsertTCheSta(this.txt车牌号.Text, this.txt日期.Text, this.txt时间_Hour.Text
                                                 , this.txt车辆运营状态CD.Text, this.txt车辆运输状态CD.Text
                                                 , this.txt车辆装载状态CD.Text
                                                 , this.txt车辆装载率.Text
                                                 , this.txt省市CD.Text
                                                 , this.txt路段名.Text, this.txt详细路段.Text
                                                 , this.txt备注.Text
                                                 );
            if (!isInserted)
            {
                //登记失败
                this.SetMessage("GTH003", "IGTH003002", MSG_LEVEL.Error);
                this.AddCssClass(this.txt车牌号, CSS_TEXT_ERROR);
                this.AddCssClass(this.txt日期, CSS_TEXT_ERROR);
                this.AddCssClass(this.txt时间_Hour, CSS_TEXT_ERROR);
                this.txt车牌号.Focus();
            }
            else
            {
                //登记成功
                this.SetMessage("GTH003", "IGTH003000", MSG_LEVEL.Info);
                this.txt车牌号.Focus();
            }
            #endregion

            #endregion
        }
        else if (this.txt处理区分.Text == "3") //处理区分为1(订正)的场合
        {
            #region
            //订正时，各个控件的属性进行控制
            proc清空_Init(this.txt处理区分.Text);


            //车牌号的值进行检查
            #region
            if (this.txt车牌号.Text.Trim() == string.Empty)
            {
                //车牌号为空的场合,退出登陆
                this.SetMessage("ZDH002", "IZDH002000", MSG_LEVEL.Error);
                this.AddCssClass(this.txt车牌号, CSS_TEXT_ERROR);
                this.AddCssClass(this.txt日期, CSS_TEXT_ERROR);
                this.AddCssClass(this.txt时间_Hour, CSS_TEXT_ERROR);
                return;
            }
            else
            {
                //对车牌号进行查询
                CZDH003 instanceSelectTChe = new CZDH003();
                ZDH003DS.T_CHE_STADataTable dtSelectTChe = instanceSelectTChe.GetT_CHE_STADetail(this.txt车牌号.Text, this.txt日期.Text, this.txt时间_Hour.Text);
                if (dtSelectTChe.Count <= 0)
                {
                    //车牌号不存在场合,退出登陆
                    this.SetMessage("ZDH002", "IZDH002007", MSG_LEVEL.Error);
                    this.AddCssClass(this.txt车牌号, CSS_TEXT_ERROR);
                    this.AddCssClass(this.txt日期, CSS_TEXT_ERROR);
                    this.AddCssClass(this.txt时间_Hour, CSS_TEXT_ERROR);
                    this.txt车牌号.Focus();
                    return;
                }
            }
            #endregion
            
            //执行更新
            #region
            Boolean isChanged = false;
            CZDH003 instance = new CZDH003();
            isChanged = instance.UpdateTCheSta( this.txt车辆运营状态CD.Text, this.txt车辆运输状态CD.Text
                                                 , this.txt车辆装载状态CD.Text
                                                 , this.txt车辆装载率.Text
                                                 , this.txt省市CD.Text
                                                 , this.txt路段名.Text, this.txt详细路段.Text
                                                 , this.txt备注.Text
                                                 , this.txt车牌号.Text, this.txt日期.Text, this.txt时间_Hour.Text
                                                 );
            if (!isChanged)
            {
                //更新失败
                this.SetMessage("ZDH002", "IZDH002007", MSG_LEVEL.Error);
                this.AddCssClass(this.txt车牌号, CSS_TEXT_ERROR);
                this.AddCssClass(this.txt日期, CSS_TEXT_ERROR);
                this.AddCssClass(this.txt时间_Hour, CSS_TEXT_ERROR);
                this.txt车牌号.Focus();
                return;
            }
            else
            {
                //更新成功
                this.SetMessage("GTH001", "IGTH001000", MSG_LEVEL.Info);
                this.txt处理区分.Focus();
            }
            #endregion

            #endregion
        }
        else if (this.txt处理区分.Text == "9") //处理区分为1(删除)的场合
        {
            #region
            ////删除时，各个控件的属性进行控制
            ////proc清空_Init(this.txt处理区分.Text);

            ////车牌号的值进行检查
            #region
            if (this.txt车牌号.Text.Trim() == string.Empty)
            {
                //车牌号为空的场合,退出登陆
                this.SetMessage("ZDH002", "IZDH002000", MSG_LEVEL.Error);
                this.AddCssClass(this.txt车牌号, CSS_TEXT_ERROR);
                return;
            }
            else
            {
                //对车牌号进行查询
                CZDH003 instanceSelectTChe = new CZDH003();
                ZDH003DS.T_CHE_STADataTable dtSelectTChe = instanceSelectTChe.GetT_CHE_STADetail(this.txt车牌号.Text, this.txt日期.Text, this.txt时间_Hour.Text);
                if (dtSelectTChe.Count <= 0)
                {
                    //车牌号不存在场合,退出登陆
                    this.SetMessage("ZDH002", "IZDH002007", MSG_LEVEL.Error);
                    this.AddCssClass(this.txt车牌号, CSS_TEXT_ERROR);
                    this.AddCssClass(this.txt日期, CSS_TEXT_ERROR);
                    this.AddCssClass(this.txt时间_Hour, CSS_TEXT_ERROR);
                    this.txt车牌号.Focus();
                    return;
                }
            }
            #endregion

            ////执行删除
            Boolean isDeleted = false;
            CZDH003 instance = new CZDH003();
            isDeleted = instance.DeleteTCheSta(this.txt车牌号.Text, this.txt日期.Text, this.txt时间_Hour.Text);
            if (!isDeleted)
            {
                //删除失败
                this.SetMessage("ZDH002", "IZDH002007", MSG_LEVEL.Error);
                this.AddCssClass(this.txt车牌号, CSS_TEXT_ERROR);
                this.AddCssClass(this.txt日期, CSS_TEXT_ERROR);
                this.AddCssClass(this.txt时间_Hour, CSS_TEXT_ERROR);
                this.txt车牌号.Focus();
                return;
            }
            else
            {
                //删除成功
                this.SetMessage("GTH004", "IGTH004000", MSG_LEVEL.Info);
                this.txt车牌号.Focus();
            }

            #endregion
        }
        else //处理区分为上述以外的场合
        {
            this.SetMessage("GTH000", "IGTH000002", MSG_LEVEL.Error);
            return;
        }

    }

    protected void proc清空_Init(string str处理区分)
    {
        Label lblMsgCD = (Label)Master.FindControl("lblMsgCD");
        Label lblMsg = (Label)Master.FindControl("lblMsg");
        lblMsgCD.Text = "";
        lblMsg.Text = "";
        //this.SetMessage("", "", MSG_LEVEL.Info);

        //初期化
        if (str处理区分 == "0")
        {
            //控件的Enabled进行控制
            #region
            this.txt处理区分.Enabled = true;

            this.txt车牌号.Enabled = true;
            this.txt日期.Enabled = true;
            this.txt时间_Hour.Enabled = true;

            this.txt车辆运营状态CD.Enabled = false;
            this.txt车辆运营状态.Enabled = false;
            this.txt车辆运输状态CD.Enabled = false;
            this.txt车辆运输状态.Enabled = false;
            this.txt车辆装载状态CD.Enabled = false;
            this.txt车辆装载状态.Enabled = false;
            this.txt车辆装载率.Enabled = false;

            this.txt省市CD.Enabled = false;
            this.txt省市.Enabled = false;

            this.txt路段名.Enabled = false;
            this.txt详细路段.Enabled = false;
            this.txt备注.Enabled = false;
            #endregion

            //控件的Text进行清空
            #region
            this.txt处理区分.Text = string.Empty;
            this.txt处理区分.Focus();

            this.txt车牌号.Text = string.Empty;
            this.txt日期.Text = string.Empty;
            this.txt时间_Hour.Text = string.Empty;

            this.txt车辆运营状态CD.Text = string.Empty;
            this.txt车辆运营状态.Text = string.Empty;
            this.txt车辆运输状态CD.Text = string.Empty;
            this.txt车辆运输状态.Text = string.Empty;
            this.txt车辆装载状态CD.Text = string.Empty;
            this.txt车辆装载状态.Text = string.Empty;
            this.txt车辆装载率.Text = string.Empty;

            this.txt省市CD.Text = string.Empty;
            this.txt省市.Text = string.Empty;

            this.txt路段名.Text = string.Empty;
            this.txt详细路段.Text = string.Empty;
            this.txt备注.Text = string.Empty;
            #endregion
        }

        //查询
        if (str处理区分 == "1")
        {
            //控件的Enabled进行控制
            #region
            this.txt处理区分.Enabled = true;

            this.txt车牌号.Enabled = true;
            this.txt日期.Enabled = true;
            this.txt时间_Hour.Enabled = true;

            this.txt车辆运营状态CD.Enabled = false;
            this.txt车辆运营状态.Enabled = false;
            this.txt车辆运输状态CD.Enabled = false;
            this.txt车辆运输状态.Enabled = false;
            this.txt车辆装载状态CD.Enabled = false;
            this.txt车辆装载状态.Enabled = false;
            this.txt车辆装载率.Enabled = false;

            this.txt省市CD.Enabled = false;
            this.txt省市.Enabled = false;

            this.txt路段名.Enabled = false;
            this.txt详细路段.Enabled = false;
            this.txt备注.Enabled = false;
            #endregion

            //控件的Text进行清空
            #region
            this.txt车牌号.Focus();
            this.txt车辆运营状态CD.Text = string.Empty;
            this.txt车辆运营状态.Text = string.Empty;
            this.txt车辆运输状态CD.Text = string.Empty;
            this.txt车辆运输状态.Text = string.Empty;
            this.txt车辆装载状态CD.Text = string.Empty;
            this.txt车辆装载状态.Text = string.Empty;
            this.txt车辆装载率.Text = string.Empty;

            this.txt省市CD.Text = string.Empty;
            this.txt省市.Text = string.Empty;

            this.txt路段名.Text = string.Empty;
            this.txt详细路段.Text = string.Empty;
            this.txt备注.Text = string.Empty;
            #endregion
        }

        //登记或订正
        if (str处理区分 == "2" || str处理区分 == "3")
        {
            //控件的Enabled进行控制
            #region
            this.txt处理区分.Enabled = true;

            this.txt车牌号.Enabled = true;
            this.txt日期.Enabled = true;
            this.txt时间_Hour.Enabled = true;

            this.txt车辆运营状态CD.Enabled = true;
            this.txt车辆运营状态.Enabled = false;
            this.txt车辆运输状态CD.Enabled = true;
            this.txt车辆运输状态.Enabled = false;
            this.txt车辆装载状态CD.Enabled = true;
            this.txt车辆装载状态.Enabled = false;

            this.txt车辆装载率.Enabled = true;

            this.txt省市CD.Enabled = true;
            this.txt省市.Enabled = false;

            this.txt路段名.Enabled = true;
            this.txt详细路段.Enabled = true;
            this.txt备注.Enabled = true;
            #endregion

            //控件的Text进行清空
            #region

            #endregion
        }

        //删除
        if (str处理区分 == "9")
        {
            //控件的Enabled进行控制
            #region
            this.txt处理区分.Enabled = true;

            this.txt车牌号.Enabled = true;
            this.txt日期.Enabled = true;
            this.txt时间_Hour.Enabled = true;

            this.txt车辆运营状态CD.Enabled = false;
            this.txt车辆运营状态.Enabled = false;
            this.txt车辆运输状态CD.Enabled = false;
            this.txt车辆运输状态.Enabled = false;
            this.txt车辆装载状态CD.Enabled = false;
            this.txt车辆装载状态.Enabled = false;
            this.txt车辆装载率.Enabled = false;

            this.txt省市CD.Enabled = false;
            this.txt省市.Enabled = false;

            this.txt路段名.Enabled = false;
            this.txt详细路段.Enabled = false;
            this.txt备注.Enabled = false;
            #endregion

            //控件的Text不进行清空
            #region

            #endregion
        }
    }

    protected void txt处理区分_TextChange(object sender, EventArgs e)
    {
        Label lblMsgCD = (Label)Master.FindControl("lblMsgCD");
        Label lblMsg = (Label)Master.FindControl("lblMsg");

        //处理区分为空的场合
        if (this.txt处理区分.Text == string.Empty)
        {
            String msg = MessageUtil.GetMessage("GTH000", "IGTH000001");
            lblMsgCD.Text = "IGTH000001";
            lblMsg.Text = msg;
            return;
        }
        //处理区分为1,2,3,9的场合
        else if (this.txt处理区分.Text == "1" || this.txt处理区分.Text == "2" ||
            this.txt处理区分.Text == "3" || this.txt处理区分.Text == "9")
        {
            this.proc清空_Init(this.txt处理区分.Text);
        }
        //处理区分为上述以外的场合
        else
        {
            String msg = MessageUtil.GetMessage("GTH000", "IGTH000002");
            lblMsgCD.Text = "IGTH000002";
            lblMsg.Text = msg;
            return;
        }

    }

    protected void btn清除_Click(object sender, EventArgs e)
    {
        //初期化处理
        #region
        //查询时，各个控件的属性进行控制
        proc清空_Init("0");
        #endregion
    }

}